package com.share.rest;

import com.share.domain.User;
import com.share.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @desc:
 * @author:caifan
 * @date:2020/3/15
 */
@RestController
@RequestMapping("/rest/user")
public class UserRest {
    @Autowired
    private UserService userService;

    @RequestMapping(value = "/save1", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public void save1(@RequestBody User user) {
        if (null == user.getUpdateTime()) {
            user.setUpdateTime(new Date());
        }
        userService.saveUser1(user);
    }

    @RequestMapping(value = "/save2", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public void save2(@RequestBody User user) {
        if (null == user.getUpdateTime()) {
            user.setUpdateTime(new Date());
        }
        userService.saveUser2(user);
    }
}
